/**
 * 
 */
package no.hio.wsprovider.services;

import static org.junit.Assert.*;

import java.util.List;
import java.util.NoSuchElementException;

import junit.framework.TestCase;

import no.hio.wsprovider.dao.ProductDAO;
import no.hio.wsprovider.services.ProductServiceImpl;
import no.hio.wsprovider.vo.Product;

import org.junit.Before;
import org.junit.Test;

/**
 * @author andreas
 *
 */
public class ProductServiceImplTestCase extends TestCase implements ProductDAO {

	Product p1, p2;
	ProductServiceImpl productService;
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		p1 = new Product();
		p2 = new Product();
		
		p1.setProductID(0);
		p2.setProductID(2);
		p1.setTitle("Product 1");
		p2.setTitle("Product 2");
		p2.setDescription("Description 1");
		p2.setDescription("Description 2");
		productService = new ProductServiceImpl();
		productService.setProductDAO(this);
	
	}

	

	/**
	 * Test method for {@link no.hio.wsprovider.services.ProductServiceImpl#insertProduct(no.hio.wsprovider.vo.Product)}.
	 */
	@Test
	public void testInsertProductSuccess() {
		
		
		assertEquals(1, productService.insertProduct(p1));
		
	}
	
	@Test
	public void testInsertProductFail() {
		
		assertEquals(-1,productService.insertProduct(p2));
	}

	/**
	 * Test method for {@link no.hio.wsprovider.services.ProductServiceImpl#updateProduct(no.hio.wsprovider.vo.Product)}.
	 */
	@Test
	public void testUpdateProduct() {
		productService.updateProduct(p1);
		productService.updateProduct(p2);
				
	}
	
	@Test
	public void testRemoveProduct()
	{
		productService.removeProduct(p1);
		productService.removeProduct(p2);
	}
	


	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#findAll()
	 */
	@Override
	public List<Product> findAll() {
		return null;
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#findbyDescription(java.lang.String)
	 */
	@Override
	public List<Product> findbyDescription(String description) {
		return null;
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#findByProductID(int)
	 */
	@Override
	public Product findByProductID(int productID) {
		return null;
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#findByTitle(java.lang.String)
	 */
	@Override
	public List<Product> findByTitle(String title) {
		return null;
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#insert(no.hio.wsprovider.vo.Product)
	 */
	@Override
	public int insert(Product p) throws UnsupportedOperationException {
		
		
		if(p.getProductID() == 0) return 1;
		throw new UnsupportedOperationException();
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#remove(no.hio.wsprovider.vo.Product)
	 */
	@Override
	public void remove(Product p) throws NoSuchElementException {
		if(p.getProductID() == 0) throw new NoSuchElementException();
	}

	/* (non-Javadoc)
	 * @see no.hio.wsprovider.dao.ProductDAO#update(no.hio.wsprovider.vo.Product)
	 */
	@Override
	public void update(Product p) throws NoSuchElementException {
		
		if(p.getProductID() == 0) throw new NoSuchElementException();
		
	}

}
